package com.avic.rong.adapter.show;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.activity.ArticleDetailActivity;
import com.avic.rong.bean.show_bean.TypeBean;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

/**
 * 关注
 * Creater: Created by wangyz on 2017/1/10.
 * Email: 936804097@qq.com
 */

public class RecommendwendaAdapter extends RecyclerView.Adapter<RecommendwendaAdapter.RecommendViewHolder> {


    private static final int STYPE_NO_PICTURE = 0;
    private static final int STYPE_ONE_PICTURE = 1;
    private static final int STYPE_THREE_PICTURE = 3;

    private Context mContext;
    private List<TypeBean> data = new ArrayList<>();

    public RecommendwendaAdapter(Context context) {
        this.mContext = context;
    }

    public void setData( List<TypeBean> list){
        this.data = list;
        notifyDataSetChanged();
    }

    @Override
    public RecommendwendaAdapter.RecommendViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.wenda_view_command, parent, false);
        if (viewType == STYPE_ONE_PICTURE){
            view = LayoutInflater.from(mContext).inflate(R.layout.wenda_view_command_one, parent, false);
        }else if(viewType == STYPE_THREE_PICTURE){
            view = LayoutInflater.from(mContext).inflate(R.layout.wenda_view_command_three, parent, false);
        }

        return new RecommendViewHolder(view) ;
    }

    @Override
    public void onBindViewHolder(RecommendwendaAdapter.RecommendViewHolder holder, int position) {
        TypeBean datas = data.get(position);
        String coverImgOne = data.get(position).getCoverImgOne();
        String coverImgtwo = data.get(position).getCoverImgTwo();
        String img = data.get(position).getImg();




        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int viewNum = data.get(position).getViewNum();
                viewNum++;
                data.get(position).setViewNum(viewNum);
                notifyDataSetChanged();
                Intent intent=new Intent(mContext, ArticleDetailActivity.class);
                int contId = data.get(position).getId();
                intent.putExtra("contId",contId);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemViewType(int position) {
        String coverImgOne = data.get(position).getCoverImgOne();
        String coverImgTwo = data.get(position).getCoverImgTwo();
        String img = data.get(position).getImg();

        if (coverImgOne != null && coverImgTwo != null) {
            if (!coverImgOne.equals("") && !coverImgTwo.equals("")) {
                return STYPE_THREE_PICTURE;
            } else if (!img.equals("")) {
                return STYPE_ONE_PICTURE;
            }
            return STYPE_NO_PICTURE;
        } else if (img != null) {
            if (!img.equals("")) {
                return STYPE_ONE_PICTURE;
            }
            return STYPE_NO_PICTURE;
        }
        return STYPE_NO_PICTURE;


    }

    @Override
    public int getItemCount() {
        if (data!=null){
            return data.size();
        }
        return 0;
    }



    class RecommendViewHolder extends RecyclerView.ViewHolder {



        TextView list_wenda_title,list_wenda_name,list_wenda_size;
        ImageView list_wenda_image,list_wenda_oneimage,list_wenda_threeimage,list_wenda_twoimage;
        public RecommendViewHolder(View itemView) {
            super(itemView);

            list_wenda_image =itemView.findViewById(R.id.list_wenda_image);
            list_wenda_oneimage =itemView.findViewById(R.id.list_wenda_oneimage);
            list_wenda_threeimage =itemView.findViewById(R.id.list_wenda_threeimage);
            list_wenda_title =itemView.findViewById(R.id.list_wenda_title);
            list_wenda_name =itemView.findViewById(R.id.list_wenda_name);
            list_wenda_size =itemView.findViewById(R.id.list_wenda_size);
            list_wenda_twoimage =itemView.findViewById(R.id.list_wenda_twoimage);


        }
    }
}
